package com.collect.tanzania.zhiScene.zhiAuditer.zhiFollow.zhiD0;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.collect.tanzania.R;
import com.collect.tanzania.zhiAdater.zhiCustomerOrder.ZHICustomerOrderAdjuster;
import com.collect.tanzania.zhiBase.BaseFragment;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRCustomerBankAccountEntity;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRCustomerRepayOrderListEntity;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRPartRepayListEntity;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRRepaymentLinkEntity;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRWarnLetterEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISCaseRecordEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISCustomerMarkedOrder;
import com.collect.tanzania.zhiBean.zhiSend.ZHISCustomerRepayOrderListEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISPartRepayListEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISRepaymentLinkEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISSendSmsEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISSendWarnLetterEntity;
import com.collect.tanzania.zhiGlobal.zhiAppSettings.ZHIProjectConstants;
import com.collect.tanzania.zhiGlobal.zhiAppSettings.ZHIProjectRouter;
import com.collect.tanzania.zhiHelper.ZHIMainProcessHelper;
import com.collect.tanzania.zhiHelper.ZHISysShareHelper;
import com.collect.tanzania.zhiScene.zhiCollection.zhiDetail.ZHIDetailActivity;
import com.collect.tanzania.zhiScene.zhiRemind.zhiCustomer.zhiMember.zhiRoot.ZHICustomerOrderType;
import com.collect.tanzania.zhiScene.zhiRemind.zhiCustomer.zhiMember.zhiRoot.ZHIRootCustomerFragmentInterface;
import com.collect.tanzania.zhiScene.zhiWidget.zhiDialog.ZHIDialogChangeAmount;
import com.collect.tanzania.zhiScene.zhiWidget.zhiDialog.ZHIDialogMessage;
import com.collect.tanzania.zhiScene.zhiWidget.zhiDialog.ZHIDialogPartRepay;
import com.collect.tanzania.zhiScene.zhiWidget.zhiSendSmsView.ZHISendRepaymentLinkView;
import com.collect.tanzania.zhiScene.zhiWidget.zhiSendSmsView.ZHISendSmsClickListener;
import com.collect.tanzania.zhiScene.zhiWidget.zhiSendSmsView.ZHISendSmsLinkView;
import com.collect.tanzania.zhiScene.zhiWidget.zhiSendSmsView.ZHISendWarnLetterView;
import com.collect.tanzania.zhiScene.zhiWidget.zhiSubmitRecTagView.ZHISubmitRecFollowView;
import com.collect.tanzania.zhiUtils.StringUtil;
import com.collect.tanzania.zhiUtils.ToastUtil;

import java.util.ArrayList;
import java.util.Objects;

import butterknife.BindView;

@SuppressLint("NonConstantResourceId")
public class ZHIAuditerD0Fragment extends BaseFragment<ZHIAuditerD0Presenter> implements ZHIAuditerD0Contract.View {

    @BindView(R.id.srl_swipe_layout)
    SwipeRefreshLayout srl_swipe_layout;

    @BindView(R.id.rc_list)
    RecyclerView rc_list;

    @BindView(R.id.iv_filter)
    ImageView iv_filter;
    @BindView(R.id.iv_words)
    ImageView iv_words;

    @BindView(R.id.tv_query_count)
    TextView tv_query_count;

    private String mUserProduct = "";
    private String mUserOrderId = "";
    private String mUserId = "";
    public String mUserName;
    public String mUserMobile;
    public String mProductName;
    public String mRepaymentAmount;

    private final int mOrderType = ZHICustomerOrderType.TYPE_TODAY;

    private ZHISubmitRecFollowView mZHISubmitRecFollowView;
    private ZHIDialogChangeAmount mZHIDialogChangeAmount;
    private ZHISendRepaymentLinkView mZHISendRepaymentLinkView;
    private ZHISendSmsLinkView mZHISendSmsLinkView;
    private ZHISendWarnLetterView mZHISendWarnLetterView;

    private ZHIRootCustomerFragmentInterface mZHIRootCustomerFragmentInterface;

    private final ZHICustomerOrderAdjuster mZHICustomerOrderAdjuster = new ZHICustomerOrderAdjuster();

    private ArrayList<ZHIRCustomerRepayOrderListEntity> mCustomerRepayOrderListEntityArrayList;

    @SuppressLint("StaticFieldLeak")
    private static ZHIAuditerD0Fragment mInstance;

    public static ZHIAuditerD0Fragment getInstance(){
        return mInstance;
    }

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_auditer_d0;
    }

    @Override
    protected void initView(View view) {
        try {
            mInstance = this;
            srl_swipe_layout.setColorSchemeColors(getResources().getColor(R.color.theme_color_0));
            mZHISendSmsLinkView = new ZHISendSmsLinkView(getActivity());
            mZHISendSmsLinkView.setOnSendSmsLinkClickListener(new ZHISendSmsClickListener() {
                @Override
                public void onSendSmsClick(String content) {
                    ZHISSendSmsEntity zhiSSendSmsEntity = getSendSmsParamsV2(content);
                    Log.d(TAG, "onSendSmsClick: " + content);
                    assert mPresenter != null;
                    mPresenter.sendTagSmsV2(getActivity(), zhiSSendSmsEntity);
                }

                @Override
                public void onSendSmsWithWhatsAppClick(String mobile, String content) {
//                    ZHISysShareHelper.sendMsgWithWhatsApp(requireActivity(),  ZHIProjectConstants.PRE_AREA_FLAG + mobile, content);

                    String relation = "";
                    ZHISCaseRecordEntity zhiSCaseRecordEntity = getCaseRecordParamsForWhatsapp(mZHISendSmsLinkView.getName(), mobile, relation);
                    assert mPresenter != null;
                    mPresenter.caseRecordForWhatsapp(getActivity(), zhiSCaseRecordEntity, content);
                }
            });

            mZHISubmitRecFollowView = new ZHISubmitRecFollowView(getActivity());
            mZHISubmitRecFollowView.setSubmitRecFollowItemClickListener(ctsCustomerMarkedOrder -> {
                if (ctsCustomerMarkedOrder != null && mPresenter != null) {
                    mPresenter.markCustomerRepayOrder(getActivity(), ctsCustomerMarkedOrder, true);
                }
            });

            iv_filter.setOnClickListener(v -> showFilter());
            iv_words.setOnClickListener(v -> ZHIProjectRouter.toWordsSkills());

            mZHIDialogChangeAmount = new ZHIDialogChangeAmount(getActivity());
            mZHISendRepaymentLinkView = new ZHISendRepaymentLinkView(getActivity());
            mZHISendWarnLetterView = new ZHISendWarnLetterView(getActivity());
            mZHISendRepaymentLinkView = new ZHISendRepaymentLinkView(getActivity());

//            mOrderType = tbl_segment.getCurIndex();
//            tbl_segment.setZHITabBarItemClickListener(index -> {
//                mOrderType = index;
//                initData(true);
//            });

            initEvent();
            initData(true);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

//        try {
//            mZHIRootCustomerFragmentInterface = (ZHIRootCustomerFragmentInterface) activity;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onGetErrorInfo() {
        srl_swipe_layout.setRefreshing(false);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onGetLatestCustomerRepayOrderListV2(ArrayList<ZHIRCustomerRepayOrderListEntity> zhirRCustomerRepayOrderListEntityArrayList) {
        try {
            srl_swipe_layout.setRefreshing(false);
            mCustomerRepayOrderListEntityArrayList = zhirRCustomerRepayOrderListEntityArrayList;
            mZHICustomerOrderAdjuster.setNewData(mCustomerRepayOrderListEntityArrayList);
            tv_query_count.setText("Total:" + mCustomerRepayOrderListEntityArrayList.size());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onGetPartRepayList(ArrayList<ZHIRPartRepayListEntity> arrayList) {
        try {
            if (arrayList != null && arrayList.size() > 0) {
                ZHIDialogPartRepay.showDataSource(getActivity(), arrayList);
            } else {
                ToastUtil.s("No partial repayment data yet.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onGetUserVirtualAccount(ZHISPartRepayListEntity zhiSPartRepayListEntity, ZHIRCustomerBankAccountEntity zhirCustomerBankAccountEntity) {
        try {
            if (mCustomerRepayOrderListEntityArrayList != null) {
                int mposition = -1;
                for (int i = 0; i < mCustomerRepayOrderListEntityArrayList.size(); i++) {
                    ZHIRCustomerRepayOrderListEntity zhirCustomerRepayOrderListEntity = mCustomerRepayOrderListEntityArrayList.get(i);
                    if (zhirCustomerRepayOrderListEntity.getOrderId().equalsIgnoreCase(zhiSPartRepayListEntity.getOrderId())) {
                        mposition = i;
                        zhirCustomerRepayOrderListEntity.setVirtualBankName(zhirCustomerBankAccountEntity.getBankName());
                        zhirCustomerRepayOrderListEntity.setVirtualBankAccount(zhirCustomerBankAccountEntity.getBankAccount());
                    }
                }

                if (mposition >= 0) {
                    Log.d(TAG, "onGetUserVirtualAccount: "+mposition);
                    mZHICustomerOrderAdjuster.refreshNotifyItemChanged(mposition);
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onMarkCustomerRepayOrder() {
        mZHISubmitRecFollowView.dismiss();
        initData(true);
    }

    @Override
    public void onGetRepayLink(ZHIRRepaymentLinkEntity zhirRepaymentLinkEntity) {
        try {
            String mRepaymentLink = StringUtil.safeString(zhirRepaymentLinkEntity.getLink());
            //发还款链接
            showSendRepaymentLinkView(mUserName, mUserMobile, mProductName, mRepaymentLink);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onSendTagSmsV2() {
        ToastUtil.s("SMS sent successfully");
    }

    @Override
    public void onSendTagSmsLink() {
        ToastUtil.s("SMS sent successfully");
    }

    @Override
    public void onCaseRecordForWhatsapp(String contactMobile, String content) {
        try {
            ZHISysShareHelper.sendMsgWithWhatsApp(getActivity(), ZHIProjectConstants.PRE_AREA_FLAG + contactMobile, content);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    @Override
    public void onGetUserDemandLetterPdfUrl(ZHIRWarnLetterEntity zhirWarnLetterEntity) {
        if (zhirWarnLetterEntity.isTodaySendFlag()) {
            ZHIDialogMessage.showDialog(requireActivity(), "Prompt", zhirWarnLetterEntity.getTips(), true, tag -> {});
            return;
        }
        showSendWarnLetterView(mUserMobile, zhirWarnLetterEntity.getWhatsappMsg());
    }

    @SuppressLint("InflateParams")
    public void initEvent() {
        try {
            srl_swipe_layout.setOnRefreshListener(() -> initData(false));
            mZHICustomerOrderAdjuster.setEmptyView(getRefreshEmptyView());
            rc_list.setLayoutManager(new GridLayoutManager(this.getActivity(), 1));
            rc_list.setAdapter(mZHICustomerOrderAdjuster);

            mZHICustomerOrderAdjuster.setOnCTCustomerOrderAdjusterItemClickListener((type, zhirRCustomerRepayOrderListEntity) -> {
                mUserName = zhirRCustomerRepayOrderListEntity.getFullName();
                mUserMobile = zhirRCustomerRepayOrderListEntity.getMobile();
                mUserProduct = zhirRCustomerRepayOrderListEntity.getProduct();
                mUserOrderId = zhirRCustomerRepayOrderListEntity.getOrderId();
                mUserId = zhirRCustomerRepayOrderListEntity.getUserId();
                mProductName = zhirRCustomerRepayOrderListEntity.getProduct();
                mRepaymentAmount = zhirRCustomerRepayOrderListEntity.getRepayAmount();

                if (type == ZHICustomerOrderAdjuster.CustomerOrderAdjusterItemClickType.TYPE_WHATSAPP) {
                    if (mPresenter != null) {
                        ZHISCustomerMarkedOrder zhiSCustomerMarkedOrder = new ZHISCustomerMarkedOrder();
                        zhiSCustomerMarkedOrder.setMobile(zhirRCustomerRepayOrderListEntity.getMobile());
                        zhiSCustomerMarkedOrder.setFullName(zhirRCustomerRepayOrderListEntity.getFullName());
                        zhiSCustomerMarkedOrder.setRemark("whatsapp");
                        zhiSCustomerMarkedOrder.setOrderId(zhirRCustomerRepayOrderListEntity.getOrderId());
                        zhiSCustomerMarkedOrder.setType(getCaseSearchParams().getType());
                        mPresenter.markCustomerRepayOrder(getActivity(), zhiSCustomerMarkedOrder, false);
                    }
                } else if (type == ZHICustomerOrderAdjuster.CustomerOrderAdjusterItemClickType.TYPE_REPAID) {
                    if (mPresenter != null) {
                        mPresenter.getPartRepayList(getActivity(), new ZHISPartRepayListEntity(zhirRCustomerRepayOrderListEntity.getOrderId()));
                    }
                } else if (type == ZHICustomerOrderAdjuster.CustomerOrderAdjusterItemClickType.TYPE_BANK_ACCOUNT) {
                    Log.d(TAG, "mUserOrderId: "+mUserOrderId);
                    //显示输入框
                    showChangeRepayAmountDialog();
//                    if (mPresenter != null) {
//                        mPresenter.getUserVirtualAccount(getActivity(), new ZHISPartRepayListEntity(zhirRCustomerRepayOrderListEntity.getOrderId()));
//                    }
                } else if (type == ZHICustomerOrderAdjuster.CustomerOrderAdjusterItemClickType.TYPE_FOLLOW) {
                    showSendSmsView(zhirRCustomerRepayOrderListEntity);

                } else if (type == ZHICustomerOrderAdjuster.CustomerOrderAdjusterItemClickType.TYPE_WARN_LETTER) {
                    if (mPresenter != null) {
                        mPresenter.getUserDemandLetterPdfUrl(requireActivity(), new ZHISSendWarnLetterEntity(mUserOrderId, "NO"));
                    }
                }
            });

            mZHISendRepaymentLinkView.setOnSendRepaymentLinkClickListener(new ZHISendSmsClickListener() {
                @Override
                public void onSendSmsClick(String content) {
                    ZHISSendSmsEntity zhisSendSmsEntity = getSendSmsLinkParams(content);
                    assert mPresenter != null;
                    mPresenter.sendTagSmsLink(getActivity(), zhisSendSmsEntity);
                }

                @Override
                public void onSendSmsWithWhatsAppClick(String mobile, String content) {
                    String relation = "";
                    ZHISCaseRecordEntity zhiSCaseRecordEntity = getCaseRecordParamsForWhatsapp(mZHISendRepaymentLinkView.getName(), mobile, relation);
                    assert mPresenter != null;
                    mPresenter.caseRecordForWhatsapp(requireActivity(), zhiSCaseRecordEntity, content);
                }
            });

            mZHISendWarnLetterView.setOnSendSmsClickListener(new ZHISendSmsClickListener() {
                @Override
                public void onSendSmsClick(String content) {

                }

                @Override
                public void onSendSmsWithWhatsAppClick(String mobile, String content) {
                    ZHIDialogMessage.showDialog(requireActivity(), "Prompt", "Has it been successfully sent to the customer?", "NO", "YES", tag -> {
                        if (mPresenter != null) {
                            String sendFlag = "NO";
                            if (tag == 1) {
                                sendFlag = "YES";
                            }
                            mPresenter.getUserDemandLetterPdfUrl(requireActivity(), new ZHISSendWarnLetterEntity(mUserOrderId, sendFlag));
                        }
                    });
                    new Handler(Looper.getMainLooper()).postDelayed(() -> ZHISysShareHelper.sendMsgWithWhatsApp(getActivity(), ("255" + mobile), content), 800);
                }
            });
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initData(boolean showLoading) {
        if (mPresenter != null) {
            ZHISCustomerRepayOrderListEntity zhisCustomerRepayOrderListEntity;

            if (mOrderType == ZHICustomerOrderType.TYPE_TODAY) {
                zhisCustomerRepayOrderListEntity = getD0CaseSearchParams();
            } else {
                zhisCustomerRepayOrderListEntity = getD1CaseSearchParams();
            }

            if (zhisCustomerRepayOrderListEntity == null) {
                srl_swipe_layout.setRefreshing(false);
                return;
            }

            mPresenter.getLatestCustomerRepayOrderListV2(getActivity(), zhisCustomerRepayOrderListEntity, showLoading);
        }
    }

    /**
     * 显示send warn letter view
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020/9/8 09:27
     */
    @SuppressLint("InflateParams")
    private void showSendWarnLetterView(String contact, String content) {
        try {
            if (mZHISendWarnLetterView == null) {
                mZHISendWarnLetterView = new ZHISendWarnLetterView(getActivity());
                mZHISendWarnLetterView.setFragmentManager(getChildFragmentManager());
            }
            View parentView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_auditer_d0, null);
            mZHISendWarnLetterView.setmParentView(parentView);
            mZHISendWarnLetterView.setContact(contact);
            mZHISendWarnLetterView.setPreContent(content);
            mZHISendWarnLetterView.showAtLocation(parentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private View getRefreshEmptyView() {
        View emptyView = getLayoutInflater().inflate(R.layout.view_empty_no_data, null);
        emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        emptyView.setOnClickListener(v -> {
            initData(true);
        });
        return emptyView;
    }

    @SuppressLint("InflateParams")
    private void showSendSmsView(ZHIRCustomerRepayOrderListEntity zhirRCustomerRepayOrderListEntity) {
        try {
            if (mZHISubmitRecFollowView == null) {
                mZHISubmitRecFollowView = new ZHISubmitRecFollowView(getActivity());
            }
            View parentView = LayoutInflater.from(getActivity()).inflate(R.layout.activity_root_customer_service, null);
            mZHISubmitRecFollowView.setmParentView(parentView);
            mZHISubmitRecFollowView.setName(zhirRCustomerRepayOrderListEntity.getFullName());
            mZHISubmitRecFollowView.setContact(zhirRCustomerRepayOrderListEntity.getMobile());
            mZHISubmitRecFollowView.setOrderId(zhirRCustomerRepayOrderListEntity.getOrderId());
            mZHISubmitRecFollowView.setType(getCaseSearchParams().getType());
            mZHISubmitRecFollowView.showAtLocation(parentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void refreshData() {
        initData(true);
    }

    public void showFilter() {
        if (mZHIRootCustomerFragmentInterface != null) {
            mZHIRootCustomerFragmentInterface.onShowFilterFollow();
        }
    }

    public ZHISCustomerRepayOrderListEntity getCaseSearchParams() {
        if (mZHIRootCustomerFragmentInterface != null) {
            return mZHIRootCustomerFragmentInterface.onGetFollowFilterParams();
        }
        return new ZHISCustomerRepayOrderListEntity();
    }

    public ZHISCustomerRepayOrderListEntity getD0CaseSearchParams() {
        if (mZHIRootCustomerFragmentInterface != null) {
            return mZHIRootCustomerFragmentInterface.onGetFollowFilterD0Params();
        }
        return new ZHISCustomerRepayOrderListEntity();
    }

    public ZHISCustomerRepayOrderListEntity getD1CaseSearchParams() {
        if (mZHIRootCustomerFragmentInterface != null) {
            return mZHIRootCustomerFragmentInterface.onGetFollowFilterD1Params();
        }
        return new ZHISCustomerRepayOrderListEntity();
    }


    /**
     * 显示send sms link view
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020/9/8 09:27
     */
    @SuppressLint("InflateParams")
    private void showSendSmsLinkView(String name, String contact, String productName, String smsLink) {
        try {
            if (TextUtils.isEmpty(smsLink)) {
                return;
            }
            if (mZHISendSmsLinkView == null) {
                mZHISendSmsLinkView = new ZHISendSmsLinkView(getActivity());
                mZHISendSmsLinkView.setFragmentManager(Objects.requireNonNull(getActivity()).getSupportFragmentManager());
            }
            View parentView = LayoutInflater.from(getActivity()).inflate(R.layout.activity_root_customer_service, null);
            mZHISendSmsLinkView.setmParentView(parentView);
            mZHISendSmsLinkView.setName(name);
            mZHISendSmsLinkView.setContact(contact);
            mZHISendSmsLinkView.setSmsLink(productName, smsLink);
            mZHISendSmsLinkView.showAtLocation(parentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @NonNull
    private ZHISSendSmsEntity getSendSmsParamsV2(String content) {
        return new ZHISSendSmsEntity(mUserProduct, ZHIMainProcessHelper.getInstance().getFullName(), mUserMobile, content, mUserOrderId);
    }


    @NonNull
    private ZHISCaseRecordEntity getCaseRecordParamsForWhatsapp(String name, String contact, String relation) {
        ZHISCaseRecordEntity zhiSCaseRecordEntity = new ZHISCaseRecordEntity();
        zhiSCaseRecordEntity.setAppId(mUserProduct);
        zhiSCaseRecordEntity.setUserId(mUserId);
        zhiSCaseRecordEntity.setOrderId(mUserOrderId);
        zhiSCaseRecordEntity.setSysLoginName(ZHIMainProcessHelper.getInstance().getFullName());
        zhiSCaseRecordEntity.setRemark("whatsapp");

        zhiSCaseRecordEntity.setContactMobile(contact);
        zhiSCaseRecordEntity.setContactName(name);
        zhiSCaseRecordEntity.setContactRelation(relation);
        zhiSCaseRecordEntity.setContactResult("");
        zhiSCaseRecordEntity.setPtpTime("");

        return zhiSCaseRecordEntity;
    }


    private void showChangeRepayAmountDialog() {
        if (mZHIDialogChangeAmount == null) {
            mZHIDialogChangeAmount = new ZHIDialogChangeAmount(getActivity());
        }
//        mZHIDialogChangeAmount.setOriAmount(mOriAmount);
        mZHIDialogChangeAmount.setOriAmount("10");
        mZHIDialogChangeAmount.setDefaultAmount(mRepaymentAmount);
        mZHIDialogChangeAmount.setOnClickButtonListener(changeAmount -> {
            if (!TextUtils.isEmpty(changeAmount)) {
                //获取还款链接
                assert mPresenter != null;
                ZHISRepaymentLinkEntity zhiSRepaymentLinkEntity = getRepaymentLinkParams(changeAmount);
                mPresenter.getRepayLink(getActivity(), zhiSRepaymentLinkEntity);
            }
        });
        mZHIDialogChangeAmount.show();
    }

    private ZHISRepaymentLinkEntity getRepaymentLinkParams(String amount) {
        ZHISRepaymentLinkEntity zhiSRepaymentLinkEntity = new ZHISRepaymentLinkEntity(mUserId, mUserOrderId);
        if (!TextUtils.isEmpty(amount)) {
            zhiSRepaymentLinkEntity.setChangeRepayType();
            zhiSRepaymentLinkEntity.setRepayAmount(amount);
        }
        return zhiSRepaymentLinkEntity;
    }


    /**
     * 显示send repayment link view
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020/9/8 09:27
     */
    @SuppressLint("InflateParams")
    private void showSendRepaymentLinkView(String name, String contact, String productName, String repaymentLink) {
        try {
            if (TextUtils.isEmpty(repaymentLink)) {
                return;
            }
            if (mZHISendRepaymentLinkView == null) {
                mZHISendRepaymentLinkView = new ZHISendRepaymentLinkView(getActivity());
                mZHISendRepaymentLinkView.setFragmentManager(requireActivity().getSupportFragmentManager());
            }
            View parentView = LayoutInflater.from(requireActivity()).inflate(R.layout.fragment_auditer_d0, null);
            mZHISendRepaymentLinkView.setmParentView(parentView);
            mZHISendRepaymentLinkView.setName(name);
            mZHISendRepaymentLinkView.setContact(contact);
            mZHISendRepaymentLinkView.setRepaymentLink(productName, repaymentLink);
            mZHISendRepaymentLinkView.showAtLocation(parentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @NonNull
    private ZHISSendSmsEntity getSendSmsLinkParams(String content) {
        return new ZHISSendSmsEntity(mProductName, mUserId, mUserMobile, content, mUserOrderId);
    }
}